package com.sn.springboot_netty.ip;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

/**
 * @Author fyy
 * @Description
 * @Date 2020/12/1 16:19
 */
public class InetAddressUtil {

    public static void main(String[] args) throws UnknownHostException {
        InetAddress address = InetAddress.getLocalHost();
        System.out.println("字节数组形式的IP地址：" + Arrays.toString(address.getAddress()));
        System.out.println("计算机名称：" + address.getHostName());
        System.out.println("IP地址：" + address.getHostAddress());
        //根据ip地址或者计算机名称获取信息
        InetAddress address2 = InetAddress.getByName("192.168.249.1");
        System.out.println("计算机名" + address2.getHostName());
        System.out.println("IP地址" + address2.getHostAddress());
    }

}
